#delimit

cd "/nfs/home/A/awhite/shared_space/gscourts/lawproject/replication/output";
capture log using LS09_10_Analysis.log, replace;

u "/nfs/home/A/awhite/shared_space/gscourts/lawproject/replication/Constitutional_Attitudes_2009_2010_Merged_Data_Client.dta", clear;

/* DEMOGRAPHICS */

gen white = ppethm ==1;
gen black = ppethm ==2;
gen hisp = ppethm ==3;

/* KNOWLEDGE */

gen know_chief_09 = Q11==5 if Q11 !=.;
gen dk_chief_09 = Q11==.;
gen know_souter_09 = Q12==7;
gen dk_souter_09 = Q12==.;
gen know_party_09 = Q501==2;
gen dk_party = Q501==3;
egen know = rmean(know_chief_09 know_souter_09 know_party_09);

/*  ISSUES  	*/

/* 2009	*/


/* Issue Agreement */

/* Eminent Domain */

gen     domain_agree =  1 if (Q301==1&Q215==1)|(Q301==2&Q215==2);
replace domain_agree = -1 if (Q301==2&Q215==1)|(Q301==1&Q215==2);
replace domain_agree =  .5 if (Q301a==1&Q215==1)|(Q301a==2&Q215==2);
replace domain_agree = -.5 if (Q301a==2&Q215==1)|(Q301a==1&Q215==2);
replace domain_agree = 0 if Q301a==3;
replace domain_agree = . if Q301==.|Q215==.;

gen domain_ns = Q301==3 if Q301!=.;

gen domain_realagree= 0;
replace domain_realagree= 1 if Q215==1;
replace domain_realagree= -1 if Q215==2;

gen domain_realagree_flat = domain_realagree;
recode domain_realagree_flat (0 = .) (-1 = 0);

gen domain_correct_flat = .;
replace domain_correct_flat = 0 if (Q301a != . ) |(Q301 != . ) ;
replace domain_correct_flat = 1 if Q301==1 | Q301a==1;

gen domain_pagree_flat = .;
replace domain_pagree_flat = 0 if  domain_agree <=0;
replace domain_pagree_flat = 1 if domain_agree >0;


/* Death Penalty */

gen     dp_agree =  1 if (Q207b==2&Q302==2)|(Q302==1&Q207b==1);
replace dp_agree = -1 if (Q302==1&Q207b==2)|(Q302==2&Q207b==1);
replace dp_agree =  .5 if (Q302a==2&Q207b==2)|(Q302a==1&Q207b==1);
replace dp_agree = -.5 if (Q302a==1&Q207b==2)|(Q302a==2&Q207b==1);
replace dp_agree = 0 if Q302a==3;
replace dp_agree =  . if Q302==.|Q207b==.;

gen dp_ns = Q302==3 if  Q302!=.;

gen dp_realagree= 0;
replace dp_realagree= 1 if Q207b==2;
replace dp_realagree= -1 if Q207b==1;

gen dp_realagree_flat = dp_realagree;
recode dp_realagree_flat (0 = .) (-1 = 0);

gen dp_correct_flat = .;
replace dp_correct_flat = 0 if (Q302a != .) |(Q302 != . ); 
replace dp_correct_flat = 1 if Q302==2 | Q302a==2;

gen dp_pagree_flat = .;
replace dp_pagree_flat = 0 if  dp_agree <=0;
replace dp_pagree_flat = 1 if dp_agree >0;


/* Habeas Corpus for Foreign Detainees */

gen     hc_agree =  1 if (Q214==1&Q303==1)|(Q303==2&Q214==2);
replace hc_agree = -1 if (Q303==2&Q214==1)|(Q303==1&Q214==2);
replace hc_agree =  .5 if (Q303a==1&Q214==1)|(Q303a==2&Q214==2);
replace hc_agree = -.5 if (Q303a==2&Q214==1)|(Q303a==1&Q214==2);
replace hc_agree = 0 if Q303a==3;
replace hc_agree =  . if Q303==.|Q214==.;

gen hc_ns = Q303==3 if Q303!=.;

gen hc_correct_flat = .;
replace hc_correct_flat = 0 if (Q303 != .) |(Q303a != . ); 
replace hc_correct_flat = 1 if Q303==1 | Q303a==1;

gen hc_pagree_flat = .;
replace hc_pagree_flat = 0 if  hc_agree <=0;
replace hc_pagree_flat = 1 if hc_agree >0;

gen hc_realagree= 0;
replace hc_realagree= 1 if Q214==1;
replace hc_realagree= -1 if Q214==2;

gen hc_realagree_flat = hc_realagree;
recode hc_realagree_flat (0 = .) (-1 = 0);

/* Hand Gun - Heller */

gen     gun_agree =  1 if ((Q209==1|Q209==2)&Q304==1)|(Q304==2&(Q209==3|Q209==4));
replace gun_agree =  -1 if ((Q209==1|Q209==2)&Q304==2)|(Q304==1&(Q209==3|Q209==4));
replace gun_agree =  .5 if ((Q209==1|Q209==2)&Q304a==1)|(Q304a==2&(Q209==3|Q209==4));
replace gun_agree = -.5 if ((Q209==1|Q209==2)&Q304a==2)|(Q304a==1&(Q209==3|Q209==4));
replace gun_agree = 0 if Q304a==3;
replace gun_agree =  . if Q209==.|Q304==.;

gen gun_ns = Q304==3 if Q304!=.;

gen gun_correct_flat = .;
replace gun_correct_flat = 0 if (Q304 != .) |(Q304a != . ); 
replace gun_correct_flat = 1 if Q304==1 | Q304a==1;

gen guns_pagree_flat = .;
replace guns_pagree_flat = 0 if  gun_agree <=0;
replace guns_pagree_flat = 1 if gun_agree >0;

gen gun_realagree= 0;
replace gun_realagree= 1 if Q209==3 | Q209==4;
replace gun_realagree= -1 if Q209==1 | Q209==2;

gen guns_realagree_flat = gun_realagree;
recode guns_realagree_flat (0 = .) (-1 = 0);

/* Sodomy Laws */

gen     gay_agree =  1 if (Q305==1&Q206==2)|(Q305==2&Q206==1);
replace gay_agree = -1 if (Q305==2&Q206==2)|(Q305==1&Q206==1);
replace gay_agree =  .5 if (Q305a==1&Q206==2)|(Q305a==2&Q206==1);
replace gay_agree = -.5 if (Q305a==2&Q206==2)|(Q305a==1&Q206==1);
replace gay_agree = 0 if Q305a==3;
replace gay_agree = . if Q305==.|Q206==.;

gen gay_ns = Q305==3 if Q305!=.;

gen gay_correct_flat = .;
replace gay_correct_flat = 0 if (Q305 != .) |(Q305a != . ); 
replace gay_correct_flat = 1 if Q305==1 | Q305a==1;

gen gay_pagree_flat = .;
replace gay_pagree_flat = 0 if  gay_agree <=0;
replace gay_pagree_flat = 1 if gay_agree >0;

gen gay_realagree= 0;
replace gay_realagree= 1 if Q206==2;
replace gay_realagree= -1 if Q206==1;

gen gay_realagree_flat = gay_realagree;
recode gay_realagree_flat (0 = .) (-1 = 0);


/* Roe */

gen roe_agree = 1 if Q212==1|Q212==2;
replace roe_agree = -1 if Q212==3|Q212==4;
replace roe_agree = . if Q212==.;

/* Agree Score */

egen agree_score_09 = rmean(gun_agree hc_agree gay_agree dp_agree domain_agree);
egen ns_score_09 = rmean(gun_ns hc_ns gay_ns dp_ns domain_ns);

egen agree_score_09_realagree = rmean(gun_realagree hc_realagree gay_realagree dp_realagree domain_realagree);
egen agree_score_09_realagree_flat = rmean(guns_realagree_flat hc_realagree_flat gay_realagree_flat dp_realagree_flat domain_realagree_flat);

egen agree_score_09_flat = rmean(guns_pagree_flat hc_pagree_flat gay_pagree_flat dp_pagree_flat domain_pagree_flat);

egen correctness_09_flat = rmean(gun_correct_flat hc_correct_flat gay_correct_flat dp_correct_flat domain_correct_flat);



/*  2010 */

/* Citizens United */

/* CU 1 means Pro Corporate Free Speech */

/* Perception of Court*/

gen CU_court = 0 if Q520_2010==3;
replace CU_court = 1 if Q520_2010==2|Q520a_2010==2;
replace CU_court = -1 if Q520_2010==1|Q520a_2010==1;

gen CU_ns = Q520_2010==3 if Q520_2010!=. ;

gen CU_correct_flat = .;
replace CU_correct_flat = 0 if (Q520_2010 != .) |(Q520a_2010 != . ); 
replace CU_correct_flat = 1 if Q520_2010==2 | Q520a_2010==2;

/* Preference */

gen CU_self = 0 if Q512F_2010==-1;
replace CU_self = 1 if Q512F_2010==1|Q512F_2010==2;
replace CU_self = -1 if Q512F_2010==3|Q512F_2010==4;

/* set up agreement as in 2009 and 2012*/
gen CU_agree = 1 if (Q520_2010==2 & Q512F_2010==1)|(Q520_2010==2 & Q512F_2010==2)| (Q520_2010==1 & Q512F_2010==3)|(Q520_2010==1 & Q512F_2010==4);
replace CU_agree = .5 if (Q520a_2010==2 & Q512F_2010==1)|(Q520a_2010==2 & Q512F_2010==2)| (Q520a_2010==1 & Q512F_2010==3)|(Q520a_2010==1 & Q512F_2010==4);
replace CU_agree = 0 if Q520_2010==3 & Q520a_2010==-1;
replace CU_agree = -.5 if (Q520a_2010==1 & Q512F_2010==1)|(Q520a_2010==1 & Q512F_2010==2)| (Q520a_2010==2 & Q512F_2010==3)|(Q520a_2010==2 & Q512F_2010==4);
replace CU_agree = -1 if (Q520_2010==1 & Q512F_2010==1)|(Q520_2010==1 & Q512F_2010==2)| (Q520_2010==2 & Q512F_2010==3)|(Q520_2010==2 & Q512F_2010==4);
replace CU_agree = . if Q520_2010==.| Q512F_2010==.;


/* Violent Videos */

/* VV 1 means Pro Free Speech */

/* Perception of Court*/

gen VV_court = 0 if Q521_2010==3;
replace VV_court = 1 if Q521_2010==2|Q521a_2010==2;
replace VV_court = -1 if Q521_2010==1|Q521a_2010==1;

gen VV_ns = Q521_2010==3 if Q521_2010!=.;

gen VV_correct_flat = .;
replace VV_correct_flat = 0 if (Q521_2010 != .) |(Q521a_2010 != . ); 
replace VV_correct_flat = 1 if Q521_2010==2 | Q521a_2010==2;

/* Preference */

gen VV_self = 0 if Q512C_2010==-1;
replace VV_self = 1 if Q512C_2010==1|Q512C_2010==2;
replace VV_self = -1 if Q512C_2010==3|Q512C_2010==4;


/* set up agreement as in 2009 and 2012*/
gen VV_agree = 1 if (Q521_2010==2 & Q512C_2010==1)|(Q521_2010==2 & Q512C_2010==2)|(Q521_2010==1 & Q512C_2010==3)|(Q521_2010==1 & Q512C_2010==4);
replace VV_agree = .5 if (Q521a_2010==2 & Q512C_2010==1)|(Q521a_2010==2 & Q512C_2010==2)|(Q521a_2010==1 & Q512C_2010==3)|(Q521a_2010==1 & Q512C_2010==4);
replace VV_agree = 0 if Q521_2010==3 & Q521a_2010==-1;
replace VV_agree = -.5 if (Q521a_2010==1 & Q512C_2010==1)|(Q521a_2010==1 & Q512C_2010==2)|(Q521a_2010==2 & Q512C_2010==3)|(Q521a_2010==2 & Q512C_2010==4);
replace VV_agree = -1 if (Q521_2010==1 & Q512C_2010==1)|(Q521_2010==1 & Q512C_2010==2)|(Q521_2010==2 & Q512C_2010==3)|(Q521_2010==2 & Q512C_2010==4);
replace VV_agree = . if Q521_2010==.|Q512C_2010==.;


/* Life Sentences for Those Under 18 */
/* LS 1 means Anti Life Sentence */

/* Perception of Court*/

gen LS_court = 0 if Q522_2010==3;
replace LS_court = 1 if Q522_2010==2|Q522a_2010==2;
replace LS_court = -1 if Q522_2010==1|Q522a_2010==1;
gen LS_ns =  Q522_2010==3 if  Q522_2010!=.;

gen LS_correct_flat = .;
replace LS_correct_flat = 0 if (Q522_2010 != .) |(Q522a_2010 != . ); 
replace LS_correct_flat = 1 if Q522_2010==2 | Q522a_2010==2;

/* Preference */

gen LS_self = 0 if Q511E_2010==-1;
replace LS_self = 1 if Q511E_2010==1|Q511E_2010==2;
replace LS_self = -1 if Q511E_2010==3|Q511E_2010==4;

/* set up agreement as in 2009 and 2012*/
gen LS_agree = 1 if (Q522_2010==2 & Q511E_2010==1)|(Q522_2010==2 & Q511E_2010==2)|(Q522_2010==1 & Q511E_2010==3)|(Q522_2010==1 & Q511E_2010==4);
replace LS_agree = .5 if (Q522a_2010==2 & Q511E_2010==1)|(Q522a_2010==2 & Q511E_2010==2)|(Q522a_2010==1 & Q511E_2010==3)|(Q522a_2010==1 & Q511E_2010==4);
replace LS_agree = 0 if Q522_2010==3 & Q522a_2010==-1;
replace LS_agree = -.5 if (Q522a_2010==1 & Q511E_2010==1)|(Q522a_2010==1 & Q511E_2010==2)|(Q522a_2010==2 & Q511E_2010==3)|(Q522a_2010==2 & Q511E_2010==4);
replace LS_agree = -1 if (Q522_2010==1 & Q511E_2010==1)|(Q522_2010==1 & Q511E_2010==2)|(Q522_2010==2 & Q511E_2010==3)|(Q522_2010==2 & Q511E_2010==4);
replace LS_agree = . if Q522_2010==.|Q511E_2010==.;


/* EPA Authority to Regulate Carbon */
/* EP 1 means for EPA */

/* Perception of Court*/

gen EP_court = 0 if Q523_2010==3;
replace EP_court = 1 if Q523_2010==1|Q523a_2010==1;
replace EP_court = -1 if Q523_2010==2|Q523a_2010==2;
gen EP_ns = Q523_2010==3 if Q523_2010!=.;

gen EP_correct_flat = .;
replace EP_correct_flat = 0 if (Q523_2010 != .) |(Q523a_2010 != . ); 
replace EP_correct_flat = 1 if Q523_2010==1 | Q523a_2010==1;

/* Preference */

gen EP_self = 0 if Q511A_2010==-1;
replace EP_self = 1 if Q511A_2010==1|Q511A_2010==2;
replace EP_self = -1 if Q511A_2010==3|Q511A_2010==4;

/* set up agreement as in 2009 and 2012*/
gen EP_agree = 1 if (Q523_2010==1 & Q511A_2010==1)|(Q523_2010==1 & Q511A_2010==2)|(Q523_2010==2 & Q511A_2010==3)|(Q523_2010==2 & Q511A_2010==4);
replace EP_agree = .5 if (Q523a_2010==1 & Q511A_2010==1)|(Q523a_2010==1 & Q511A_2010==2)|(Q523a_2010==2 & Q511A_2010==3)|(Q523a_2010==2 & Q511A_2010==4);
replace EP_agree = 0 if Q523_2010==3 & Q523a_2010==-1;
replace EP_agree = -.5 if (Q523a_2010==2 & Q511A_2010==1)|(Q523a_2010==2 & Q511A_2010==2)|(Q523a_2010==1 & Q511A_2010==3)|(Q523a_2010==1 & Q511A_2010==4);
replace EP_agree = -1 if (Q523_2010==2 & Q511A_2010==1)|(Q523_2010==2 & Q511A_2010==2)|(Q523_2010==1 & Q511A_2010==3)|(Q523_2010==1 & Q511A_2010==4);
replace EP_agree = . if Q523_2010==.|Q511A_2010==.;


/* Roe */
gen roe_agree_2010 = 1 if Q510_2010==1|Q510_2010==2;
replace roe_agree_2010 = -1 if Q510_2010==3|Q510_2010==4;
replace roe_agree_2010 = . if Q510_2010==.;


/* Issue Agreement */

gen CU_agree_flat = CU_agree;
recode CU_agree_flat (-1= 0)(-.5= 0)(.5=1);
gen VV_agree_flat = VV_agree;
recode VV_agree_flat (-1= 0)(-.5= 0)(.5=1);
gen LS_agree_flat = LS_agree;
recode LS_agree_flat (-1= 0)(-.5= 0)(.5=1);
gen EP_agree_flat = EP_agree;
recode EP_agree_flat (-1= 0)(-.5= 0)(.5=1);

gen CU_realagree = CU_self;
gen VV_realagree = VV_self;
gen LS_realagree = LS_self;
gen EP_realagree = EP_self;

gen CU_realagree_flat = CU_realagree;
recode CU_realagree_flat (-1= 0);
gen VV_realagree_flat = VV_realagree;
recode VV_realagree_flat (-1= 0);
gen LS_realagree_flat = LS_realagree;
recode LS_realagree_flat (-1= 0);
gen EP_realagree_flat = EP_realagree;
recode EP_realagree_flat (-1= 0);


egen agree_score_10 = rmean(CU_agree VV_agree LS_agree EP_agree);
egen agree_score_10_flat = rmean(CU_agree_flat VV_agree_flat LS_agree_flat EP_agree_flat);

egen agree_score_10_realagree = rmean(CU_realagree VV_realagree LS_realagree EP_realagree);

egen realagree_10_flat = rmean(CU_realagree_flat VV_realagree_flat LS_realagree_flat EP_realagree_flat);
egen correct_10_flat = rmean(CU_correct_flat VV_correct_flat LS_correct_flat EP_correct_flat);

egen ns_score = rmean(CU_ns VV_ns LS_ns EP_ns);

gen originalism = .;
replace originalism = Q502BB_2010 if Q502BB_2010 >= 0;
recode originalism (1=0)(2=0)(3=1)(4=1);

gen originalism_09 = . ;
replace originalism_09 = Q101;
recode originalism_09 (2=0);

/* Party */
gen SC_party = 0 if Q508_2010!=.; //this is 2010 question 
replace SC_party = 1 if Q508_2010==2;
replace SC_party = -1 if Q508_2010==1;
gen SC_party_dk = SC_party==0 if Q508_2010!=.;

gen pid = 0 if partyid7 !=. ; //this is 2009
replace pid = 1 if partyid7<4;
replace pid = -1 if partyid7>4&partyid7<8;
gen indie=pid==0;

gen pid_10 = 0 if Q7_2010!=. ;
replace pid_10 = 1 if Q7_2010==1; 
replace pid_10 = -1 if Q7_2010==2;
gen indie_10 = pid_10==0;

gen SC_party_09 = 0 if Q501!=.;
replace SC_party_09 = 1 if Q501==2;
replace SC_party_09 = -1 if Q501==1;
gen SC_party_dk_09 = SC_party_09==0;

gen SC_partycorrect09 = .;
replace SC_partycorrect09 =  0 if Q501 != 2 & Q501 !=.;
replace SC_partycorrect09 = 1 if Q501 == 2;

gen SC_partycorrect10 = .;
replace SC_partycorrect10 = 0 if Q508_2010 != 2 & Q508_2010 !=.;
replace SC_partycorrect10 = 1 if Q508_2010 == 2;

/*perceived party congruence*/
gen SC_samepid = SC_party*pid_10;
gen SC_samepid_09 = SC_party_09*pid;

gen SC_samepid10_flat = SC_samepid;
recode SC_samepid10_flat (-1=0);

gen SC_samepid09_flat = SC_samepid_09;
recode SC_samepid09_flat (-1=0);

/*actual party congruence*/
/*aka do you identify as a republican*/
gen SC_realsamepid_10 = pid_10;
recode SC_realsamepid_10 (-1 = 0);

gen SC_realsamepid_09 = pid;
recode SC_realsamepid_09 (-1 = 0);

gen ideology7pt_10 = Q11_2010 if Q11_2010>=0;

/* 2009 */
gen ideology7pt_09 = pppa0012 if pppa0012>=0;

gen pres_libcon = 0 if Q10==1;
replace pres_libcon = 1 if Q10==2;
replace pres_libcon = -1 if Q10==3;

gen cong_libcon = 0 if Q9==1;
replace cong_libcon = 1 if Q9==2;
replace cong_libcon = -1 if Q9==3;

gen bg = 1 if Q604_2010==1;
replace bg = 0 if Q604_2010==2|Q604_2010==3;
gen bg_ns = Q604_2010== 3;

egen agree_score = rmean(CU_agree VV_agree LS_agree EP_agree gun_agree hc_agree gay_agree gun_agree dp_agree domain_agree);
egen ns_score_all = rmean(CU_ns VV_ns LS_ns EP_ns gun_ns hc_ns gay_ns gun_ns dp_ns domain_ns);


/* Approval */

gen SC_A_2010 = 5-Q601_2010 if Q601_2010!=-1;
gen SC_A_d_2010 = 1 if SC_A_2010==4|SC_A_2010==3;
replace SC_A_d_2010 = 0 if SC_A_2010==1|SC_A_2010==2;

gen SC_A_d_2009 = Q405<3 if Q405!=.;
gen pres_A_d_2009 = Q403<3 if Q403!=.;
gen cong_A_d_2009 = Q404<3 if Q404!=.;

gen SC_A_2009 = 5- Q405 if Q405!=.;
gen pres_A_2009 = 5-Q403 if Q403!=.;
gen cong_A_2009 = 5-Q404 if Q404!=.;

gen SC_diff = SC_A_d_2010-SC_A_2009;
gen diff_agree = agree_score_10-agree_score_09;

gen pres_A_2010 = 5-Q599_2010 if Q599_2010!=-1;
gen cong_A_2010 = 5-Q600_2010 if Q600_2010!=-1;
gen pres_A_d_2010 = 1 if pres_A_2010==4|pres_A_2010==3;
replace pres_A_d_2010 = 0 if pres_A_2010==1|pres_A_2010==2;
gen cong_A_d_2010 = 1 if cong_A_2010==4|cong_A_2010==3;
replace cong_A_d_2010 = 0 if cong_A_2010==1|cong_A_2010==2;

gen congdiff09  = SC_A_2009 - cong_A_2009  if SC_A_2009!=. & cong_A_2009 !=.; //alternative outcome var.
tab congdiff09;
gen congdiff10  = SC_A_2010 - cong_A_2010  if SC_A_2010!=. & cong_A_2010 !=.; 
tab congdiff10;

set more off;


/*both 2009 and 2010 in same table; line up measures*/
label var agree_score_10 "Agreement score on cases";
label var agree_score_09 "Agreement score on cases";
label var ns_score "'Not sure' score on cases";
label var ns_score_09 "'Not sure' score on cases";
label var SC_samepid "Same party as SCOTUS (perceived)";
label var SC_samepid_09 "Same party as SCOTUS (perceived)";
label var SC_party_dk "'Not sure' of SCOTUS' partisanship";
label var SC_party_dk_09 "'Not sure' of SCOTUS' partisanship";
label var ideology7pt_10 "Ideology (7-pt)";
label var ideology7pt_09 "Ideology (7-pt)";
label var roe_agree "Agree with Roe v. Wade decision";
label var roe_agree_2010 "Agree with Roe v. Wade decision";

label var pid_10 "Party ID (3-pt)";
label var pid "Party ID (3-pt)";

label var originalism_09 "Originalism";
label var originalism "Originalism";

label var pres_A_2009 "Presidential approval";
label var pres_A_2010 "Presidential approval";

label var cong_A_2009 "Congressional approval";
label var cong_A_2010 "Congressional approval";

label var ppagecat "Age (7 categories)";
label var ppagecat_2010 "Age (7 categories)";

label var ppeducat "Education (4 categories)";
label var PPEDUCAT_2010 "Education (4 categories)";
label var SC_partycorrect09 "Knowledge: which party appointed most justices";
label var know_chief_09 "Knowledge: Chief Justice";
label var SC_partycorrect10 "Knowledge: which party appointed most justices";

//preferred specification
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 SC_partycorrect09 know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight];
outreg using replicatingtable3_both.doc, se varlabels replace;
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk SC_partycorrect10 pid_10 ideology7pt_10  originalism roe_agree_2010 pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
outreg using replicatingtable3_both.doc, se varlabels merge; /* this is Table 4 in main paper */ 

/* ordered logit? */
ologit SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 SC_partycorrect09 know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight];
outreg using ologittable.doc, se varlabels replace;
ologit SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk SC_partycorrect10 pid_10 ideology7pt_10  originalism roe_agree_2010 pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
outreg using ologittable.doc, se varlabels merge replace;

//try outputting differently
ologit SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 SC_partycorrect09 know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight];
outreg, se varlabels;
ologit SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk SC_partycorrect10 pid_10 ideology7pt_10  originalism roe_agree_2010 pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
outreg using ologittable.doc, se varlabels merge replace;

ologit SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 SC_partycorrect09 know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight];
eststo Approval2009;
ologit SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk SC_partycorrect10 pid_10 ideology7pt_10  originalism roe_agree_2010 pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
eststo Approval2010;
esttab using ologittable2.doc, se label replace;

//now split this out by party
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk SC_partycorrect10 pid_10 ideology7pt_10  originalism roe_agree_2010 pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
outreg using regs_party2010.doc, se varlabels replace;
preserve;
keep if pid_10==-1;
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk   ideology7pt_10  originalism roe_agree_2010 pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
outreg using regs_party2010.doc, se varlabels merge;
restore;
preserve;
keep if pid==1;
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk   ideology7pt_10  originalism roe_agree_2010 pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
outreg using regs_party2010.doc, se varlabels merge;
restore;

reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 SC_partycorrect09 know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight];
outreg using regs_party2009.doc, se varlabels replace;
preserve;
keep if pid==-1;
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09  know_chief_09 ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight];
outreg using regs_party2009.doc, se varlabels merge;
restore;
preserve;
keep if pid==1;
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09  know_chief_09 ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight];
outreg using regs_party2009.doc, se varlabels merge;
restore;

/*other specifications*/
reg SC_A_2009 agree_score_09 ns_score_09[pw=weight]; //bivariate
outreg using regs_alt2009.doc, se varlabels replace;

//drop cong/pres approval measures
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 SC_partycorrect09 know_chief_09 pid ideology7pt_09 originalism_09 roe_agree ppeducat ppagecat ppgender ppincimp [pw=weight];
outreg using regs_alt2009.doc, se varlabels merge;

//drop Roe
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 SC_partycorrect09 know_chief_09 pid ideology7pt_09 originalism_09 cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight];
outreg using regs_alt2009.doc, se varlabels merge;

//run the whole thing without weights
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 SC_partycorrect09 know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp;
outreg using regs_alt2009.doc, se varlabels merge;


//bivariate
reg SC_A_2010 agree_score_10  ns_score [pw=weight_2010];
outreg using regs_alt2010.doc, se varlabels replace;

//drop cong/pres approval measures
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk SC_partycorrect10 pid_10 ideology7pt_10  originalism roe_agree_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
outreg using regs_alt2010.doc, se varlabels merge;

//drop Roe
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk SC_partycorrect10 pid_10 ideology7pt_10  originalism  pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010];
outreg using regs_alt2010.doc, se varlabels merge;

//run the whole thing without weights
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk SC_partycorrect10 pid_10 ideology7pt_10  originalism roe_agree_2010 pres_A_2010 cong_A_2010  PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 ;
outreg using regs_alt2010.doc, se varlabels merge;



/* and also split out by knowledge measure-- did they get more than half of the case outcomes right?*/
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09  know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight] ;
outreg using regs_knowledge09_issues.doc,se varlabels replace ;
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09  know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight] if correctness_09_flat<=.5;
outreg using regs_knowledge09_issues, se varlabels merge ;
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09  know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight]if correctness_09_flat>.5;
outreg using regs_knowledge09_issues, se varlabels merge ;

reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk ideology7pt_10 pid_10 originalism roe_agree_2010 pres_A_2010 cong_A_2010   PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010] ;
outreg using regs_knowledge10_issues, se varlabels replace;
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk ideology7pt_10 pid_10 originalism roe_agree_2010 pres_A_2010 cong_A_2010   PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010] if correct_10_flat <=.5;
outreg using regs_knowledge10_issues, se varlabels merge;
reg SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk ideology7pt_10 pid_10 originalism roe_agree_2010 pres_A_2010 cong_A_2010   PPEDUCAT_2010 ppagecat_2010 PPGENDER_2010 PPINCIMP_2010 [pw=weight_2010] if correct_10_flat >.5;
outreg using regs_knowledge10_issues, se varlabels merge;


/*and whether they know chief justice */
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09  know_chief_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight] ;
outreg using regs_knowledge09_chief.doc,se varlabels replace ;
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight] if know_chief_09 ==0;
outreg using regs_knowledge09_chief, se varlabels merge ;
reg SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09   pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight]if know_chief_09 >0;
outreg using regs_knowledge09_chief, se varlabels merge ;
/*interaction*/
reg SC_A_2009 c.SC_A_2009#c.know_chief_09 know_chief_09 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09  pid ideology7pt_09 originalism_09 roe_agree cong_A_2009 pres_A_2009 ppeducat ppagecat ppgender ppincimp [pw=weight] ;


/*Now: output some partial tables that will later be combined with 2012 data*/

/*CREATE TABLE OF APPROVAL RATINGS*/

matrix approval = J(2, 7, .);
matrix rownames approval = responses2009 responses2010;
matrix colnames approval = SC_mean SC_se President_mean President_se Congress_mean Congress_se N;
scalar counter = 0;

svyset [pweight = weight];
foreach x of varlist SC_A_d_2009 pres_A_d_2009 cong_A_d_2009  { ;
	svy:mean `x';
	scalar counter = counter+1;
	matrix define tabres = e(b);
	matrix V = e(V) ;            // <- get the variance-covariance matrix
	matrix Var = vecdiag(V);
	matrix list V;
	matrix approval[1, counter*2 -1]=tabres[1,1];
	matrix approval[1, counter *2 ]= sqrt(V[1,1]);
	};


matrix approval[1, 7]= _N;
	
	
svyset [pweight = weight_2010];
scalar counter = 0;
foreach x of varlist SC_A_d_2010 pres_A_d_2010 cong_A_d_2010  { ;
	svy:mean `x' ;
	scalar counter = counter+1;
	matrix define tabres = e(b);
	matrix V = e(V);
	matrix Var = vecdiag(V);
	matrix list tabres;
	matrix list V;
	matrix approval[2, counter*2 -1]=tabres[1,1];
	matrix approval[2, counter *2 ]= sqrt(V[1,1]);
	};

count if QFLAG_2010==1;
matrix approval[2, 7]= r(N);
	
matrix list approval;	
matout4 approval using approval0910.mat, replace;

/*And how many people approve of ONLY the court?*/
gen courtapponly09 = 0 ; replace courtapponly09 = 1 if SC_A_d_2009==1 & pres_A_d_2009==0 & cong_A_d_2009==0;
gen courtapponly10 = 0 ; replace courtapponly10 = 1 if SC_A_d_2010==1 & pres_A_d_2010==0 & cong_A_d_2010==0;
summ courtapponly09; summ courtapponly10;

//SAME DEAL FOR ISSUE KNOWLEDGE AND CONGRUENCE
matrix issuecong = J(2, 6, .);
matrix rownames issuecong = responses2009 responses2010;
matrix colnames issuecong = CorrectSC_mean CorrectSC_se Realagree_mean Realagree_se Perceivedagree_mean Perceivedagree_se;
scalar counter = 0;

svyset [pweight = weight];
foreach x of varlist correctness_09_flat agree_score_09_realagree_flat agree_score_09_flat  { ;
	svy:mean `x' ;
	scalar counter = counter+1;
	matrix define tabres = e(b);
	matrix V = e(V);
	matrix Var = vecdiag(V);
	matrix list V;
	matrix issuecong[1, counter*2 -1]=tabres[1,1];
	matrix issuecong[1, counter *2 ]= sqrt(V[1,1]);
	};
	
svyset [pweight = weight_2010];
scalar counter = 0;
foreach x of varlist correct_10_flat realagree_10_flat agree_score_10_flat  { ;
	svy:mean `x' ;
	scalar counter = counter+1;
	matrix define tabres = e(b);
	matrix V = e(V);
	matrix Var = vecdiag(V);
	matrix list tabres;
	matrix list V;
	matrix issuecong[2, counter*2 -1]=tabres[1,1];
	matrix issuecong[2, counter *2 ]= sqrt(V[1,1]);
	};
	
matrix list issuecong;
matout4 issuecong using issuecong0910.mat, replace;

/*AND FINALLY, PARTY KNOWLEDGE AND CONGRUENCE*/
matrix partycong = J(2, 6, .);
matrix rownames partycong = responses2009 responses2010;
matrix colnames partycong = CorrectSCparty_mean CorrectSCparty_se Realpartyagree_mean Realpartyagree_se Perceivedpartyagree_mean Perceivedpartyagree_se;
scalar counter = 0;

svyset [pweight = weight];
foreach x of varlist SC_partycorrect09 SC_realsamepid_09  SC_samepid09_flat{ ;
	svy:mean `x' ;
	scalar counter = counter+1;
	matrix define tabres = e(b);
	matrix V = e(V);
	matrix Var = vecdiag(V);
	matrix list V;
	matrix partycong[1, counter*2 -1]=tabres[1,1];
	matrix partycong[1, counter *2 ]= sqrt(V[1,1]);
	};
	
svyset [pweight = weight_2010];
scalar counter = 0;
foreach x of varlist SC_partycorrect10 SC_realsamepid_10 SC_samepid10_flat{ ;
	svy:mean `x' ;
	scalar counter = counter+1;
	matrix define tabres = e(b);
	matrix V = e(V);
	matrix Var = vecdiag(V);
	matrix list tabres;
	matrix list V;
	matrix partycong[2, counter*2 -1]=tabres[1,1];
	matrix partycong[2, counter *2 ]= sqrt(V[1,1]);
	};
	
matrix list partycong;	
matout4 partycong using partycong0910.mat, replace;


/* And do a matrix to combine with 2012: var means */
	

matrix varmeans = J(17, 4, .);
//matrix rownames varmeans = responses2012;
matrix colnames varmeans = mean2009 se2009 mean2010 se2010;
scalar counter = 0;

foreach x of varlist  SC_A_2009 agree_score_09 ns_score_09 SC_samepid_09 SC_party_dk_09 originalism_09 roe_agree SC_partycorrect09 know_chief_09 ppgender ppagecat ppeducat pid ideology7pt_09 cong_A_2009 pres_A_2009 ppincimp {;
	svy:mean `x'; //34%
	scalar counter = counter+1;
	matrix define tabres = e(b);
	matrix V = e(V)  ;           // <- get the variance-covariance matrix
	matrix Var = vecdiag(V);
	matrix list V;
	matrix varmeans[counter, 1]=tabres[1,1];
	matrix varmeans[counter, 2]= sqrt(V[1,1]);
};
matrix list varmeans;
	

scalar counter = 0;

foreach x of varlist SC_A_2010 agree_score_10  ns_score SC_samepid SC_party_dk originalism roe_agree_2010 SC_partycorrect10 SC_partycorrect10 PPGENDER_2010 ppagecat_2010 PPEDUCAT_2010 pid_10 ideology7pt_10 cong_A_2010 pres_A_2010 PPINCIMP_2010{;
	svy:mean `x'; //34%
	scalar counter = counter+1;
	matrix define tabres = e(b);
	matrix V = e(V)  ;           // <- get the variance-covariance matrix
	matrix Var = vecdiag(V);
	matrix list V;
	matrix varmeans[counter, 3]=tabres[1,1];
	matrix varmeans[counter, 4]= sqrt(V[1,1]);
};
matrix rownames varmeans = "SC Approval" "Agreement Score" "Not sure of SC party" "Same party as SC (perceived)" "Don't know SC party" Originalism "Roe agreement" "SC party correct" Gender Age Education "Party ID" "Ideology (7-pt)" "Congressional approval" "Presidential approval" Income; //FILL THESE IN.
matrix list varmeans;

matout4 varmeans using varmeans0910.mat, replace;

	
	
/*also look at correctness on individual cases quickly*/
svy:tab gun_correct_flat; 
svy:tab hc_correct_flat;
svy:tab gay_correct_flat;
svy:tab dp_correct_flat;
svy:tab domain_correct_flat;
svy:tab CU_correct_flat;
svy:tab VV_correct_flat; /**/
svy:tab LS_correct_flat;
svy:tab EP_correct_flat;

svy:tab guns_pagree_flat; 
svy:tab hc_pagree_flat;
svy:tab gay_pagree_flat;
svy:tab dp_pagree_flat;
svy:tab domain_pagree_flat;
svy:tab CU_agree_flat;
svy:tab VV_agree_flat ;
svy:tab LS_agree_flat;
svy:tab EP_agree_flat;



/*Table 2 Public Preferences on Recent Cases--start with 2009*/
svyset [pweight = weight];

matrix preferences09 = J(5, 3, .);
matrix rownames preferences09 = Q215 Q207b Q214 Q206 Q209;
matrix colnames preferences09 = YES NO N;
scalar counter = 0;


foreach x of varlist Q215 Q207b Q214 Q206 {;
svy:tab `x' if `x' !=8 ; /*am now dropping the few people who don't answer about their own prefs.*/
scalar counter = counter+1;
matrix define tabres = e(b);
matrix define obs=e(N);
matrix preferences09[counter, 1]=tabres[1,1];
matrix preferences09[counter, 2]=tabres[1,2];
matrix preferences09[counter, 3]=obs[1,1];
};

svy:tab Q209 if Q209!=8; /*need to collapse categories for this one.*/
matrix define tabres = e(b);
matrix define obs=e(N);
display tabres[1,2];
scalar counter = counter+1;
matrix preferences09[counter, 1]=tabres[1,1]+tabres[1,2];
matrix preferences09[counter, 2]=tabres[1,3]+tabres[1,4];
matrix preferences09[counter, 3]=obs[1,1];

matrix list preferences09;
mat2txt, matrix(preferences09) saving(SCOTUSpreferences09.xls) title(Personal Views of Supreme Court Opinions) replace;

/*and do the same thing but with not sures included for R2*/
matrix preferences09ns = J(5, 3, .);
matrix rownames preferences09ns = Q215 Q207b Q214 Q206 Q209;
matrix colnames preferences09ns = YES NO REFUSED;
scalar counter = 0;

foreach x of varlist Q215 Q207b Q214 Q206 { ;
replace `x' = 3 if missing(`x'); /*mark missing values as something so we can see them*/
svy:tab `x' ;
scalar counter = counter+1;
matrix define tabres = e(b);
matrix preferences09ns[counter, 1]=tabres[1,1];
matrix preferences09ns[counter, 2]=tabres[1,2];
matrix preferences09ns[counter, 3]=tabres[1,3];
};

replace Q209 = 5 if missing(Q209);
svy:tab Q209 ;
matrix define tabres = e(b);
display tabres[1,2];
scalar counter = counter+1;
matrix preferences09ns[counter, 1]=tabres[1,1]+tabres[1,2];
matrix preferences09ns[counter, 2]=tabres[1,3]+tabres[1,4];
matrix preferences09ns[counter, 2]=tabres[1,3]+tabres[1,4];
matrix preferences09ns[counter, 3]=tabres[1,5];
matrix list preferences09ns;
mat2txt, matrix(preferences09ns) saving(SCOTUSpreferences09_notsures.xls) title(Personal Views of Supreme Court Opinions) replace;




/*and now 2010*/
svyset [pweight = weight_2010];

matrix preferences10 = J(4, 3, .);
matrix rownames preferences10 = Q512F_2010 Q512C_2010 Q511E_2010 Q511A_2010;
matrix colnames preferences10 = YES NO N;
scalar counter = 0;

foreach x of varlist Q512F_2010 Q512C_2010 Q511E_2010 Q511A_2010 {; 
svy:tab `x'; /*quick check on how many don't answer*/
};

foreach x of varlist Q512F_2010 Q512C_2010 Q511E_2010 Q511A_2010 {; 
svy:tab `x' if `x' !=-1 ;/*am now dropping the few people who don't answer about their own prefs.*/
scalar counter = counter+1;
matrix define tabres = e(b);
matrix define obs=e(N);
matrix preferences10[counter, 1]=tabres[1,1]+tabres[1,2];
matrix preferences10[counter, 2]=tabres[1,3]+tabres[1,4];
matrix preferences10[counter, 3]=obs[1,1];
};

matrix list preferences10;
mat2txt, matrix(preferences10) saving(SCOTUSpreferences10.xls) title(Personal Views of Supreme Court Opinions) replace;

/*and again remake for R2*/

matrix preferences10ns = J(4, 3, .);
matrix rownames preferences10ns = Q512F_2010 Q512C_2010 Q511E_2010 Q511A_2010;
matrix colnames preferences10ns = YES NO REFUSED;
scalar counter = 0;

foreach x of varlist Q512F_2010 Q512C_2010 Q511E_2010 Q511A_2010 {; 
svy:tab `x'; /* if `x' !=-1 am now dropping the few people who don't answer about their own prefs.*/
scalar counter = counter+1;
matrix define tabres = e(b);
matrix preferences10ns[counter, 1]=tabres[1,2]+tabres[1,3];
matrix preferences10ns[counter, 2]=tabres[1,4]+tabres[1,5];
matrix preferences10ns[counter, 3]=tabres[1,1];
};

matrix list preferences10ns;
mat2txt, matrix(preferences10ns) saving(SCOTUSpreferences10_notsures.xls) title(Personal Views of Supreme Court Opinions) replace;



/*perceptions matrix for 2009 and 2010*/
set more off;
svyset [pweight = weight];
matrix perceptions = J(5, 13, .);
matrix rownames perceptions = Q301 Q302 Q303 Q304 Q305 ;
matrix colnames perceptions = YES NO NOTSURE SKIPPED ALLNOTSURE PROBABLYYES PROBABLYNO STILLNOTSURE SKIPPED2 FULLYES FULLNO ALLNOTSURE2 N;
scalar counter = 0;

foreach x of varlist Q301 Q302 Q303 Q304 Q305 {; 
scalar counter = counter+1;
replace `x' = 4 if missing(`x'); 
svy:tab `x'; 
matrix list e(b);
matrix define tabres = e(b);
matrix define obs=e(N);
matrix perceptions[counter, 1]=tabres[1,1];
matrix perceptions[counter, 2]=tabres[1,2];
matrix perceptions[counter, 3]=tabres[1,3];
matrix perceptions[counter, 4]=tabres[1,4];
matrix perceptions[counter, 5]=tabres[1,3] + perceptions[counter, 4];
matrix perceptions[counter, 13]=obs[1,1];

};


matlist perceptions;
/*fill in the not-sure "probably" responses.*/
scalar counter = 0;

foreach x of varlist Q301a Q302a Q303a Q304a Q305a  {; 
svy:tab `x'; 
scalar counter = counter+1;
matrix define tabres = e(b);
matrix perceptions[counter, 6]=tabres[1,1];
matrix perceptions[counter, 7]=tabres[1,2];
matrix perceptions[counter, 8]=tabres[1,3];
matrix perceptions[counter, 9]=tabres[1,4];
matrix perceptions[counter, 10]=perceptions[counter,1] + (perceptions[counter,6]*perceptions[counter,3]); //all yeses 
matrix perceptions[counter, 11]=perceptions[counter,2] + (perceptions[counter,7]*perceptions[counter,3]) ; //all no 
matrix perceptions[counter, 12]=perceptions[counter,8]* perceptions[counter,3];  //the still-not-sure 
};

matlist perceptions;
mat2txt, matrix(perceptions) saving(SCOTUSperceptions09.xls) title(Perceptions of Supreme Court Opinions) replace;


/*now for 2010*/
set more off;
svyset [pweight = weight_2010];
matrix perceptions10 = J(4, 13, .);
matrix rownames perceptions10 = Q520_2010 Q521_2010 Q522_2010 Q523_2010;
matrix colnames perceptions10 = YES NO NOTSURE SKIPPED ALLNOTSURE PROBABLYYES PROBABLYNO STILLNOTSURE SKIPPED2 FULLYES FULLNO ALLNOTSURE2 N;
scalar counter = 0;

foreach x of varlist Q520_2010 Q521_2010 Q522_2010 Q523_2010 {; 
scalar counter = counter+1;
replace `x' = 5 if missing(`x'); 
svy:tab `x'; 
matrix list e(b);
matrix define tabres = e(b);
matrix define obs=e(N);
matrix perceptions10[counter, 1]=tabres[1,2];
matrix perceptions10[counter, 2]=tabres[1,3];
matrix perceptions10[counter, 3]=tabres[1,4];
matrix perceptions10[counter, 4]=tabres[1,1];
matrix perceptions10[counter, 5]=tabres[1,1] +tabres[1,4];
matrix perceptions10[counter, 13]=obs[1,1];
};


matlist perceptions10;
scalar counter = 0;

foreach x of varlist Q520a_2010 Q521a_2010 Q522a_2010 Q523a_2010  {; 
svy:tab `x'; 
scalar counter = counter+1;
matrix define tabres = e(b);
matrix perceptions10[counter, 6]=tabres[1,2];
matrix perceptions10[counter, 7]=tabres[1,3];
matrix perceptions10[counter, 9]=tabres[1,1];
matrix perceptions10[counter, 10]=perceptions10[counter,1] + (perceptions10[counter,6]*perceptions10[counter,5]); /*all yeses */
matrix perceptions10[counter, 11]=perceptions10[counter,2] + (perceptions10[counter,7]*perceptions10[counter,5]) ; /*all no */
matrix perceptions10[counter, 12]=perceptions10[counter,9]* perceptions10[counter,5];  /*the still-not-sure  or skippers*/
};

matlist perceptions10;

mat2txt, matrix(perceptions10) saving(SCOTUSperceptions10.xls) title(Perceptions of Supreme Court Opinions) replace;



